#ifndef EVENTDISPATCHER_H
#define EVENTDISPATCHER_H

#include <string>
#include <map>
#include <list>
#include <vector>

using namespace std;

namespace NEvent {

    class Event {
        public:
            Event(string type):_type(type) {};
            virtual ~Event();

            string getType() {return _type;}
            void setType( string _t ) {_type.swap( _t );};

        protected:
            string _type;
    };

    class EventDispatcher
    {
        public:
            typedef void(*EventFunction)(const Event*);

            EventDispatcher();
            virtual ~EventDispatcher();

            void dispatch( Event *evt );
            void addEventListener( string _type , EventFunction fn , bool once = false );
            void removeEventListener( string _type , EventFunction fn );

        protected:
        private:

            static void doAllDispatchersEvents();

            static vector< EventDispatcher* > dispatcherContainer;

            void doEvents();

            struct listenNode {
                EventFunction fn;
                bool once;
            };

            map<string,list<struct listenNode> > m_listen_list;
            list<Event*> m_event_list;
    };

}

#endif // EVENTDISPATHER_H
